<template>
	<div class="view">
		<Table
		 	border
			:height="data.height"
			:loading="data.isLoading" 
		 	:columns="columns" 
		 	:data="data.data">
		 </Table>
		<div class="pagePanel" v-show="data.data.length > 0">
			<Page
			show-sizer 
			show-elevator
			show-total
			placement="top"
			:total="data.page.totalSize" 
			:page-size="data.page.pagesize" 
			:current="data.page.currentPage + 1" 
			:page-size-opts="[20, 40, 60, 80, 100]"
			@on-change="changePage"
			@on-page-size-change="changePageSize"></Page>
		</div>
	</div>
</template>

<script>
import {formatTimestamp} from '@/common/js/date_util.js'

export default {
	props: ['data'],
	data() {
		return {
			columns: [
				{
					title: '订单编号',
					key: 'orderNo',
					align: 'center',
					width: 180
				},
				{
					title: '订单类型',
					key: 'orderType',
					align: 'center',
					width: 100,
					render: (h, params) => {
						let type = params.row.orderType;
						if (type == 1) {
							return '影厅开厅';
						} else if (type == 2) {
							return '续时消费';
						} else if (type == 3) {
							return '转厅';
						} else if (type == 4) {
							return '商品消费';
						} else if (type == 5) {
							return '会员卡充值';
						} else if (type == 6) {
							return '影厅结算';
						} else{
							return '-/-';
						}
					}
				},
				{
					title: '应收金额',
					key: 'money',
					align: 'center',
					width: 100
				},
				{
					title: '实收金额',
					key: 'getMoney',
					align: 'center',
					width: 100
				},
				// {
				// 	title: '是否授权',
				// 	key: 'isAuth',
				// 	align: 'center',
				// 	width: 100,
				// 	render: (h, params) => {
				// 		return params.row.isAuth ==0? '未授权' : '已授权'
				// 	}
				// },
				// {
				// 	title: '授权人',
				// 	key: 'authAccountName',
				// 	align: 'center',
				// 	width: 100,
				// 	render: (h, params) => {
				// 		return params.row.authAccountName != ''? params.row.authAccountName: '-/-'
				// 	}
				// },
				// {
				// 	title: '授权金额',
				// 	key: 'authMoney',
				// 	align: 'center',
				// 	width: 100,
				// 	render: (h, params) => {
				// 		return params.row.authMoney != null? params.row.authMoney: '-/-'
				// 	}
				// },
				// {
				// 	title: '授权时间',
				// 	key: 'authTime',
				// 	align: 'center',
				// 	width: 150,
				// 	render: (h, params) => {
				// 		return params.row.authTime != 0? formatTimestamp(params.row.authTime) : '-/-';
				// 	}
				// },
				{
					title: '下单时间',
					key: 'createTime',
					align: 'center',
					width: 180,
					render: (h, params) => {
						return formatTimestamp(params.row.createTime);
					}
				},
				{
					title: '订单状态',
					key: 'status',
					align: 'center',
					width: 100,
					render: (h, params) => {
						let status = params.row.status;
						if (status == 0) {
							return '未支付';
						} else if (status == 1) {
							return '已支付'
						} else if (status == 2) {
							return '支付失败'
						} else if (status == 3) {
							return '支付取消'
						} else if (status == 4) {
							return '支付超时'
						}
					}
				},
				{
					title: '支付方式',
					key: 'payType',
					align: 'center',
					width: 120,
					render: (h, params) => {
						let payType = params.row.payType;
						if (payType == 1) {
							return '会员卡支付';
						} else if (payType == 2) {
							return '现金'
						} else if (payType == 3) {
							return '银联卡'
						} else if (payType == 4) {
							return '支付宝'
						} else if (payType == 5) {
							return '微信'
						} else if (payType == 6) {
							return '信用卡'
						} else if (payType == 7) {
							return '签单'
						} else if (payType == 8) {
							return '挂账'
						} else if (payType == 9) {
							return '预付款'
						} else {
							return '-/-'
						}
					}
				},
				{
					title: '支付时间',
					key: 'payTime',
					align: 'center',
					width: 180,
					render: (h, params) => {
						return params.row.payTime != 0? formatTimestamp(params.row.payTime) : '-/-';
					}
				},
				{
					title: '挂账影厅',
					key: 'roomName',
					width: 100,
					align: 'center',
					render: (h, params) => {
						let roomName = params.row.roomName;
						if (params.row.payType == 8) {
							return params.row.roomName
						} else {
							return '-/-';
						}
					}
				},
				{
					title: '是否需要配送',
					key: 'isDeliver',
					width: 120,
					align: 'center',
					render: (h, params) => {
						let isDeliver = params.row.isDeliver;
						let orderType = params.row.orderType;
						if (orderType == 4) {
							if (isDeliver == 1) {
								return '需要配送';
							} else if (isDeliver == 0) {
								return '无配送信息';
							} else if (isDeliver == 2) {
								return '不需要配送';
							} else {
								return '-/-';
							}
						} else {
							return '-/-'
						}
					}
				},
				{
					title: '配送状态',
					key: 'deliverStatus',
					width: 100,
					align: 'center',
					render: (h, params) => {
						let status = params.row.deliverStatus;
						let orderType = params.row.orderType;
						if (orderType == 4) {
							if (status == 0) {
								return '未配送';
							} else if (status == 1) {
								return '已配送';
							} else {
								return '-/-';
							}
						}
						
					}
				},
				{
					title: '配送影厅',
					key: 'roomName',
					width: 100,
					render: (h, params) => {
						let isDeliver = params.row.isDeliver;
						let orderType = params.row.orderType;
						if (orderType == 4) {
							if (isDeliver == 1) {
								return params.row.roomName;
							} else {
								return '-/-';
							}
						} else {
							return '-/-'
						}
					}
				},
				{
					title: '操作人',
					key: 'actionName',
					align: 'center',
					width: 100,
					render: (h, params) => {
						return params.row.actionName != ''? params.row.actionName : '-/-';
					}
				},
				{
					title: '设备地址',
					key: 'deviceMac',
					align: 'center',
					width: 160,
					render: (h, params) => {
						return params.row.payTime != null? params.row.deviceMac : '-/-';
					}
				},
				{
					title: '完成时间',
					key: 'completeTime',
					align: 'center',
					width: 160,
					render: (h, params) => {
						return params.row.completeTime != 0? formatTimestamp(params.row.completeTime) : '-/-';
					}
				},
				{
					title: '操作',
					key: 'action',
					align: 'center',
					width: 200,
					render: (h, params) => {
						let detail = h('Button', {
							props: {
								type: 'primary',
								size: 'large'
							},
							on: {
								click: () => {
									
								}
							}
						}, '消费详情');
						let receipt = h('Button', {
							props: {
								type: 'primary',
								size: 'large'
							},
							on: {
								click: () => {
									
								}
							}
						}, '打印小票');
						let refund = h('Button', {
							props: {
								type: 'primary',
								size: 'large'
							},
							on: {
								click: () => {
									
								}
							}
						}, '退款');
						let deliver = h('Button', {
							props: {
								type: 'primary'
							},
							on: {
								click: () => {
									this.$emit('on-action', params);
								}
							}
						}, '配送');
						let orderType = params.row.orderType;
						let isDeliver = params.row.isDeliver;
						let deliverStatus = params.row.deliverStatus;
						if (deliverStatus == 0) {
							return h('div', [deliver]);
						} else {
							return '无操作';
						}
						
					}
				}
			],
			
		}
	},
	methods: {
		changePage(page) {
			this.$emit('on-change-page', page)
		},
		changePageSize(pagesize) {
			this.$emit('on-change-pagesize', pagesize)
		}
	}
}
</script>

<style scoped lang="less">
.page {
	.pagePanel {
		margin-top: 20px;
		text-align: center;

	}
}
</style>